package bishi.s360;

import java.util.*;

public class demo1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] arry = new int[n];
        for(int i = 0;i < n;i++) {
            arry[i] = in.nextInt();
        }
        //dp[i][j], 从第i个元素到第j个不重复元素的和
        int[][] dp = new int[n + 1][n + 1];

        for(int i = 1;i <= n;i++) {
            //记录元素
            Set<Integer> set = new HashSet<>();
            int sum = 0;
            for(int j = i;j <= n;j++) {
                int temp = arry[j - 1];
                if(!set.contains(temp)) {
                    set.add(temp);
                    sum += temp;
                }
                dp[i][j] = sum;
            }
        }
        //
        int[][] dp2 = new int[n + 1][n + 1];
        for(int i = 1;i <= n;i++) {
            dp2[i][1] = dp[1][i];
        }

        //填表
        for(int i = 2;i <= k;i++) {
            for(int j = i;j <= n;j++) {
                int temp = 0;
                for(int l = i - 1;l < j;l++) {
                    int a = dp2[l][i - 1] + dp[l + 1][j];
                    if(a > temp) {
                        temp = a;
                    }
                }
                dp2[j][i] = temp;
            }

        }
        System.out.println(dp2[n][k]);
    }
}
